<template>
	<el-drawer title="邮件详情" v-model="visible" :size="800" destroy-on-close @closed="$emit('closed')">
		<el-container v-loading="loading">
			<el-main>
				<el-form>
					<el-form-item label="发件人">
						<div style="width: 100%;">
							<el-avatar :src="form.avatar" size="small" style="margin-top: 5px;"></el-avatar>
							<span style="position: absolute;margin-left: 15px">{{form.fromUserName}}</span>
							<span style="float: right">
								<div>
									<el-icon style="margin-right: 10px;"><el-icon-clock/></el-icon>{{form.sendTime}}
								</div>
							</span>
						</div>
					</el-form-item>
					<el-form-item label="邮件标题">
						<span style="font-weight: 600;font-size: 16px">{{form.subject}}</span>
					</el-form-item>
					<el-form-item label="邮件内容">
						<div v-html="form.content"></div>
					</el-form-item>
					<el-form-item label="邮件附件" v-if="form.attachId!=''">
						<attach-menu :attachIds="form.attachId" :roleFlag="3" :preview="true"></attach-menu>
					</el-form-item>
				</el-form>
				<el-footer style="text-align: center;">
					<el-button @click="visible=false">关闭</el-button>
				</el-footer>
			</el-main>
		</el-container>
	</el-drawer>
</template>

<script>
import AttachMenu from '@/views/module/attachMenu'
export default {
	emits: ['success', 'closed'],
	components: {
		AttachMenu,
	},
	data() {
		return {
			loading: false,
			form: {
				subject:"",
				content:"",
				attachId:"",
				fromUserName:"",
				avatar:"",
				sendTime:""
			},
			model:"rece",
			visible: false,
			isSaveing: false,
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(model){
			this.model=model;
			this.visible = true;
			return this;
		},
		async setEmailReadStatus(emailId){
			await this.$API.email.setEmailReadStatus.post({emailId:emailId});
		},
		//表单注入数据
		setData(data){
			this.form.subject=data.subject
			this.form.content=data.content
			this.form.attachId=data.attachId
			this.form.fromUserName=data.fromUserName
			this.form.avatar=data.avatar
			this.form.sendTime=data.sendTime
			if(this.model=="rece")
			{
				this.setEmailReadStatus(data.emailId);
			}
		},
		async getMyEmailById(data)
		{
			let res = await this.$API.email.getMyEmailById.get({emailId:data});
			{
				if(res.code==200)
				{
					this.form.subject=res.data.subject
					this.form.content=res.data.content
					this.form.attachId=res.data.attachId
					this.form.fromUserName=res.data.fromUserName
					this.form.avatar=res.data.avatar
					this.form.sendTime=res.data.sendTime
					//this.setEmailReadStatus(data);
				}else
				{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			}
		}
	}
}
</script>

<style>
</style>
